public class ColorfulCards {
	public int[] theCards(int N, String colors) {
		char[] actual = colors.toCharArray();
		char[] possible = new char[N];
		possible[0] = 'B';
		for (int i = 2; i <= N; i++) {
			boolean prime = true;
			for (int j = 2; prime && j * j <= i; j++) {
				if (i % j == 0)
					prime = false;
			}
			possible[i - 1] = prime ? 'R' : 'B';
		}
		boolean[][] reachableLeft = new boolean[actual.length][N];
		boolean[][] reachableRight = new boolean[actual.length][N];
		for (int i = 0; i < N; i++)
			reachableLeft[0][i] = actual[0] == possible[i];
		for (int i = 1; i < actual.length; i++) {
			int startIndex = -1;
			for (int j = 0; j < N; j++) {
				if (reachableLeft[i - 1][j]) {
					startIndex = j + 1;
					break;
				}
			}
			for (int j = startIndex; j < N; j++)
				reachableLeft[i][j] = actual[i] == possible[j];
		}
		for (int i = N - 1; i >= 0; i--)
			reachableRight[actual.length - 1][i] = actual[actual.length - 1] == possible[i];
		for (int i = actual.length - 2; i >= 0; i--) {
			int startIndex = -1;
			for (int j = N - 1; j >= 0; j--) {
				if (reachableRight[i + 1][j]) {
					startIndex = j - 1;
					break;
				}
			}
			for (int j = startIndex; j >= 0; j--)
				reachableRight[i][j] = actual[i] == possible[j];
		}
		int[] numbers = new int[actual.length];
		for (int i = 0; i < actual.length; i++) {
			for (int j = 0; j < N; j++) {
				if (reachableLeft[i][j] && reachableRight[i][j]) {
					numbers[i] = numbers[i] == 0 ? j + 1 : -1;
				}
			}
		}
		return numbers;
	}


// BEGIN CUT HERE
	public static void main(String[] args) {
		if (args.length == 0) {
			ColorfulCardsHarness.run_test(-1);
		} else {
			for (int i=0; i<args.length; ++i)
				ColorfulCardsHarness.run_test(Integer.valueOf(args[i]));
		}
	}
// END CUT HERE
}

// BEGIN CUT HERE
class ColorfulCardsHarness {
	public static void run_test(int casenum) {
		if (casenum != -1) {
			if (runTestCase(casenum) == -1)
				System.err.println("Illegal input! Test case " + casenum + " does not exist.");
			return;
		}
		
		int correct = 0, total = 0;
		for (int i=0;; ++i) {
			int x = runTestCase(i);
			if (x == -1) {
				if (i >= 100) break;
				continue;
			}
			correct += x;
			++total;
		}
		
		if (total == 0) {
			System.err.println("No test cases run.");
		} else if (correct < total) {
			System.err.println("Some cases FAILED (passed " + correct + " of " + total + ").");
		} else {
			System.err.println("All " + total + " tests passed!");
		}
	}
	
	static boolean compareOutput(int[] expected, int[] result) { if (expected.length != result.length) return false; for (int i=0; i<expected.length; ++i) if (expected[i] != result[i]) return false; return true; }

	static String formatResult(int[] res) {
		String ret = "";
		ret += "{";
		for (int i=0; i<res.length; ++i) {
			if (i > 0) ret += ",";
			ret += String.format(" %d", res[i]);
		}
		ret += " }";
		return ret;
	}
	
	static int verifyCase(int casenum, int[] expected, int[] received) { 
		System.err.print("Example " + casenum + "... ");
		if (compareOutput(expected, received)) {
			System.err.println("PASSED");
			return 1;
		} else {
			System.err.println("FAILED");
			System.err.println("    Expected: " + formatResult(expected)); 
			System.err.println("    Received: " + formatResult(received)); 
			return 0;
		}
	}

	static int runTestCase(int casenum) {
		switch(casenum) {
		case 0: {
			int N                     = 5;
			String colors             = "RRR";
			int[] expected__          = {2, 3, 5 };

			return verifyCase(casenum, expected__, new ColorfulCards().theCards(N, colors));
		}
		case 1: {
			int N                     = 7;
			String colors             = "BBB";
			int[] expected__          = {1, 4, 6 };

			return verifyCase(casenum, expected__, new ColorfulCards().theCards(N, colors));
		}
		case 2: {
			int N                     = 6;
			String colors             = "RBR";
			int[] expected__          = {-1, 4, 5 };

			return verifyCase(casenum, expected__, new ColorfulCards().theCards(N, colors));
		}
		case 3: {
			int N                     = 58;
			String colors             = "RBRRBRBBRBRRBBRRBBBRRBBBRR";
			int[] expected__          = {-1, -1, -1, -1, -1, -1, -1, -1, 17, 18, 19, 23, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 47, 53 };

			return verifyCase(casenum, expected__, new ColorfulCards().theCards(N, colors));
		}
		case 4: {
			int N                     = 495;
			String colors             = "RBRRBRBBRBRRBBRRBBBRRBBBRR";
			int[] expected__          = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };

			return verifyCase(casenum, expected__, new ColorfulCards().theCards(N, colors));
		}

		// custom cases

/*      case 5: {
			int N                     = ;
			String colors             = ;
			int[] expected__          = ;

			return verifyCase(casenum, expected__, new ColorfulCards().theCards(N, colors));
		}*/
/*      case 6: {
			int N                     = ;
			String colors             = ;
			int[] expected__          = ;

			return verifyCase(casenum, expected__, new ColorfulCards().theCards(N, colors));
		}*/
/*      case 7: {
			int N                     = ;
			String colors             = ;
			int[] expected__          = ;

			return verifyCase(casenum, expected__, new ColorfulCards().theCards(N, colors));
		}*/
		default:
			return -1;
		}
	}
}

// END CUT HERE
